import { createDrawInfo, updateDrawInfo, getDrawInfo } from '@/api/draw/DrawInfoApi'
import EditBase from '@/components/TableGrid/editBase'
import {  fetchTreeGridData} from '@/api/ColumnApi'
import * as util from '@/common/utils/common'
import draw from '@/components/draw/index'


export default {
  extends: EditBase,
  name: 'drawInfoEdit',
  components: {
    draw
  },
  props:{
    columnId:{
      type: String,
      default:"-1"
    }
  },
  data() {
    return {
      domainName: '画布信息',
      editFormId: 'drawInfoEditFormId',
      formData: {},

       //以下是树相关数据
       parentTreeData: [],
       parentTreeDefaultProps: {
         children: 'children',
         label: 'label'
       },
       singleSelectTreeId: undefined,
       treeCheckNum: 0,// 用于树单选


      rules: {
				name: [{ required: true, message: '标题不能为空', trigger: 'blur' }
				],
				sortNo: [{ required: true, message: '排序不能为空', trigger: 'blur' }
				],
      }

    }
  },
  methods: {
    initDataFun(id) {
      // this.initTreeGridData();
      return getDrawInfo(id);
    },
    createDataFun() {
      // let parentTreeCheckedKeys = this.$refs.treeForm.getCheckedKeys();
      // if (parentTreeCheckedKeys.length !== 0){
      //   this.formData.columnId = parentTreeCheckedKeys[0];
      // }
      if(this.columnId === '-1'){
        this.$message({type: 'info', message: '栏目不能为空，请先选择栏目' });
        return;
      }
      this.formData.columnId = this.columnId;
      return createDrawInfo(this.formData);
    },
    // initCreate() {
    //   this.initTreeGridData();
    // },
    updateDataFun() {
      // let parentTreeCheckedKeys = this.$refs.treeForm.getCheckedKeys();
      // if (parentTreeCheckedKeys.length !== 0){
      //   this.formData.columnId = parentTreeCheckedKeys[0];
      // }else{
      //   this.formData.columnId = '-1';
      // }
      if(this.columnId === '-1'){
        this.$message({type: 'info', message: '栏目不能为空，请先选择栏目' });
        return;
      }
      this.formData.columnId = this.columnId;
      const tempData = Object.assign({}, this.formData)
      return updateDrawInfo(tempData);
    },
    // initTreeGridData() {
    //   fetchTreeGridData().then(response => {
    //     if (util.isRequestSuccess(response)) {
    //       this.parentTreeData = util.getResponseContent(response)
    //     }
    //   });
    // },
    // handleParentTreeClick(data,checked, node) {
    //   this.treeCheckNum++;
    //   if(this.treeCheckNum%2==0){
    //     if(checked){
    //       this.$refs.treeForm.setCheckedNodes([]);
    //       this.$refs.treeForm.setCheckedNodes([data]);
    //       //交叉点击节点
    //     }else{
    //       this.$refs.treeForm.setCheckedNodes([]);
    //       //点击已经选中的节点，置空
    //     }
    //   }
    // },


  }
}
